class Main extends egret.DisplayObjectContainer {
    private hajime: Hajime;


    private bg1: egret.Bitmap;
    private bg2: egret.Bitmap;
    private bg3: egret.Bitmap;

    private scroll_left: egret.Bitmap;
    private scroll_right: egret.Bitmap;
    private paper: egret.Shape;
    private contentPaper:ContentPaper;
    private contentMask:egret.Shape;


    public constructor() {
        super();
        this.hajime = new Hajime();
        this.hajime.addEventListener(GoEvent.ResourceLoaded, this.ResourceLoaded, this);
        this.addChild(this.hajime);



    }
    private ResourceLoaded(e: GoEvent) {
        this.removeChild(this.hajime);

        this.bg1 = new egret.Bitmap(RES.getRes("bg1_png"));
        this.bg2 = new egret.Bitmap(RES.getRes("bg2_png"));
        this.bg3 = new egret.Bitmap(RES.getRes("bg3_png"));
        this.bg2.y = 740 - this.bg2.height;
        this.bg3.x = 1136 - this.bg3.width;

        this.addChild(this.bg1); this.addChild(this.bg2); this.addChild(this.bg3);


        this.paper = new egret.Shape();
        this.paper.graphics.beginFill(0xbfaf93, 1);
        this.paper.graphics.drawRect(0, 0, 100, 488);
        this.paper.anchorOffsetX = this.paper.width / 2;
        this.paper.x = 1136 / 2; this.paper.y = 138;
        this.addChild(this.paper);

      

        this.contentMask=new egret.Shape();
        this.contentMask.graphics.beginFill(0x000000,1);
        this.contentMask.graphics.drawRect(0,0,936,488);
        this.contentMask.anchorOffsetX=this.contentMask.width/2;
        this.contentMask.x=1136/2;this.contentMask.y=138;
        this.addChild(this.contentMask);

        this.contentPaper=new ContentPaper();
        this.addChild(this.contentPaper);
        this.contentPaper.mask=this.contentMask;

        this.scroll_left = new egret.Bitmap(RES.getRes("scroll_left_png"));
        this.scroll_right = new egret.Bitmap(RES.getRes("scroll_right_png"));
        this.scroll_left.anchorOffsetX = this.scroll_left.width / 2;
        this.scroll_right.anchorOffsetX = this.scroll_right.width / 2;
        this.scroll_left.x = 1136 / 2 - this.scroll_left.width / 2 + 10; this.scroll_left.y = 20;
        this.scroll_right.x = 1136 / 2 + this.scroll_left.width / 2 - 10; this.scroll_right.y = 20;

        this.addChild(this.scroll_left);
        this.addChild(this.scroll_right);

        this.Start();
    }

    private Start() {
        egret.Tween.get(this.scroll_left).to({ x: 100 }, 1500, egret.Ease.cubicInOut);
        egret.Tween.get(this.scroll_right).to({ x: 1136 - 100 }, 1500, egret.Ease.cubicInOut);
        // egret.Tween.get(this.paper).to({ scaleX: 10 }, 1500, egret.Ease.cubicInOut);
        this.contentMask.scaleX=0.1;
        egret.Tween.get(this.contentMask).to({scaleX:1},1400,egret.Ease.cubicInOut);


        var keyboard = new KeyBoard();
        keyboard.addEventListener(KeyBoard.onkeydown, this.PressKey, this);
    }
    private PressKey(e) {
        if (e.data == "A") {
            this.contentPaper.GoLeft();

            egret.Tween.get(this.scroll_right).to({x:1136+50},700,egret.Ease.cubicOut);
            egret.Tween.get(this.contentMask).to({x:1136/2+50,scaleX:1.12},700,egret.Ease.cubicOut);
        }
        if (e.data == "D") {
             this.contentPaper.GoRight();
        }
    }


}